package com.indeep.user.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.indeep.user.mapper.po.AppExperienceLevelPO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AppExperienceLevelMapper extends BaseMapper<AppExperienceLevelPO> {
    @Update({
            "<script>" +
                    "UPDATE app_experience_level " +
                    "SET exp = CASE " +
                    "<foreach collection='userIds' item='userId' separator=' '>" +
                    "WHEN user_id = #{userId} THEN " +
                    "<choose>" +
                    "<when test='type == 0'>exp + 1000</when>" +
                    "<when test='type == 1'>exp + 2000</when>" +
                    "<otherwise>exp + 5000</otherwise>" +
                    "</choose>" +
                    "</foreach>" +
                    " END " +
                    "WHERE user_id IN " +
                    "<foreach collection='userIds' item='userId' open='(' close=')' separator=','>" +
                    "#{userId}" +
                    "</foreach>" +
                    "</script>"
    })
    Integer updateExperienceLevel(@Param("userIds") List<Long> userIds, @Param("type") int type);




    @Update("update app_experience_level set exp=exp+1000 where user_id = #{userId}")
    Integer addExpByComment(Long userId);




}
